﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using Microsoft.ApplicationBlocks.Data;

namespace AnyOffice.module.user_select
{
    public partial class query : BasePage
    {
        public string strUserList;
        public query()
        {
            this.strUserList = "";
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                this.ViewState["ToId"] = (Request.QueryString["ToId"] != null) ? Request.QueryString["ToId"].ToString() : "ToId";
                this.ViewState["ToName"] = (Request.QueryString["ToName"] != null) ? Request.QueryString["ToName"].ToString() : "ToName";
            }
            if (this.Page.IsPostBack)
            {
                if (this.txtUserName.Value == string.Empty)
                {
                    this.rptUser.Visible = false;
                    this.pnlNoUser.Visible = false;
                }
                else
                {
                    string commandText = "SELECT [UserId],[UserName] FROM [dbo].[Users] WHERE [UserName] LIKE '%' + @UserName + '%'";
                    SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@UserName", SqlDbType.NVarChar, 50) };
                    commandParameters[0].Value = this.txtUserName.Value;
                    DataTable table = SqlHelper.ExecuteDataset(base.Conn, CommandType.Text , commandText, commandParameters).Tables[0];
                    if (table.Rows.Count > 0)
                    {
                        for (int i = 0; i < table.Rows.Count; i++)
                        {
                            string strUserList = this.strUserList;
                            this.strUserList = strUserList + "userlist[" + i.ToString() + "]=\"" + table.Rows[i]["UserId"].ToString() + "\";\n";
                        }
                        this.rptUser.DataSource = table;
                        this.rptUser.DataBind();
                        this.rptUser.Visible = true;
                    }
                    else
                    {
                        this.pnlNoUser.Visible = true;
                    }
                }
            }
        }

 

 

    }
}
